package com.xuzimian.globaldemo.spring.security.oauth2.server.config;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
import org.springframework.security.oauth2.provider.token.DefaultTokenServices;


/**
 * 配置资源服务器：采用的是资源服务和授权服务在同一个应用中。
 * 资源服务和授权服务分离模式请参考Spring-Security-Oauth2-Resource项目。
 * 其配置了默认的DefaultTokenServices
 */
@EnableResourceServer
@Configuration
public class ResourceServerConfigurer extends ResourceServerConfigurerAdapter {
    private static final Log logger = LogFactory.getLog(ResourceServerConfigurer.class);

//    @Override
//    public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
//        resources.resourceId("risk").stateless(true);
//    }

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http.antMatcher("/api/**").authorizeRequests().anyRequest().authenticated();
    }


//    @Bean
//    public DefaultTokenServices jwtTokenServices() {
//        DefaultTokenServices services = new DefaultTokenServices();
//        return services;
//    }

}
